<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 17-3-1
 * Time: 下午9:16
 */

$fp = fopen("lock.txt","w+");
if (flock($fp,LOCK_EX)) {
    //获得写锁，写数据
    fwrite($fp, "wocao");
    // 解除锁定
    flock($fp, LOCK_UN);
} else {
    echo "file is locking...";
}
fclose($fp);